import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy, $http } = window
// ===================================================================== Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		result:{},
		// 搜索表单列表
		forms : [
			{ label:'标本条码',		name: 'spec_code' },
			{ label:'医院',			name: 'hosp_id',	  				type:'select', nameStr:'name' },
			{ label:'姓名',			name: 'patient_name' },
			{ label:'科室',			name: 'parent_project_id',			type: 'select',idStr:'uuid',	onValue:data=>$fn.onKeShi.call(this,data,{}) },
			{ label:'岗位',			name: 'project_id', 				type:'select', nameStr:'name'	},
			{ label:'录入项目时间',	names: ['start_date','end_date'], 	type:'date-range' },
		],
		
	}
	
	model = {}
	
	componentDidMount(){
		this.result()
		this.getSelect()
		if(window.isInit){
			this.fetch()
		}
	}
	
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 医院
			$fn.setRow( forms, 'hosp_id', await f.getCache({ api:'hospital' }) )
			// 科室
			$fn.setRow( forms, 'parent_project_id', await f.getCache({ api:'ke_shi' } ) )
			// 岗位
			this.resetData = await f.getCache({ api:'gang_wei' })
			$fn.setRow( forms, 'project_id', this.resetData )
			this.setState({ forms })
		})
	}
	
	result = () => $http.pull(null,'kd-report-spec/notauditreport').then(data=>{
		this.setState({result:data})
	})
	// paging
	fetch = () => $fn.fetch.call(this,'kd-report-spec/notsendreportlist')
	// 表单
		cols = [
			{ title: '标本条码', 		dataIndex: 'spec_code', 			width:120 },
			{ title: '姓名', 			dataIndex: 'patient_name',			width:100 },
			{ title: '性别', 			dataIndex: 'sex_name', 				width:100 },
			{ title: '年龄', 			dataIndex: 'newAge', 				...$fn.table.age },
			{ title: '岗位', 			dataIndex: 'project_name', 			width:120 },
			{ title: '科室', 			dataIndex: 'parent_project_name',	width:120 },
			{ title: '项目名称', 		dataIndex: 'kind_name', 			width:150 },
			{ title: '医院', 			dataIndex: 'hosp_name',				width:120 },
			{ title: '录入项目时间', 	dataIndex: 'created_at', 			width:120 },
		]
	
	
	render(){
		const { result } = this.state
		return (
			<>
				<Page title='未发报告清单'>
					{/* 搜索 */}
					{ SearchForm.call(this, {resetField: 'project_id'}) }
					{/* 表格 */}
					{ Table.call(this,
						{isInit:window.isInit, suffix: (
							<>
								<div className='ml10 g9'>未批准报告单数量 <b className='f14 c0'>{result?.num}</b></div>
							</>
						)
						}
					) }
				</Page>
			</>
		)
	}
}

export default Index